package com.hzit.controller;




import com.hzit.auth.entity.User;
import com.hzit.service.PermissionService;
import com.hzit.service.UserService;
import com.hzit.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2023-10-27
 */
@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;
	@Autowired
	private PermissionService permissionService;
	@GetMapping("/list")
	@PostAuthorize("hasAuthority('user.list')")
	public R<List<User>> list(){
		return R.ok(userService.list());
	}

	//根据用户名查询用户
	@GetMapping("/findByUsername/{username}")
	public R<User> findByUsername(@PathVariable String username){
		User user = userService.selectByUsername(username);
		R<User> ok = R.ok(user);

		return ok;
	}
	//根据用户id查询权限列表
	@GetMapping("/findPermissionListByUserId/{userId}")
	public R<List<String>> findPermissionListByUserId(@PathVariable("userId") String userId){
		List<String> permissions = permissionService.selectPermissionValueByUserId(userId);
		return R.ok(permissions);
	}
}
